home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / oop_tp55.zip / LIST1_3.PAS < prev    next >
Pascal/Delphi Source File  |  1990-03-08  |  2KB  |  133 lines

  1. { Temperature }
  2. { ------------------------------------------------------
  3.   Specification for Temperature class
  4.   Variables:
  5.             Value : real;
  6.                   The value of the temperature object is
  7.                   stored here as a real number.  The
  8.                   temperature is stored in Celsius
  9.                   degrees.
  10.  
  11.   Procedures:
  12.             .Init( T : real; DegType : char );
  13.                   The value in T is stored in the Value
  14.                   slot.  The value of DegType tells the
  15.                   object the units of the temperature being
  16.                   stored.  If the value of DegType is not
  17.                   'F' (Fahrenheit), the temperature is
  18.                   stored in degrees Celsius.
  19.  
  20.   Functions:
  21.             .GetTempC
  22.                   Returns the temperature expressed in
  23.                   Celsius.
  24.             .GetTempF
  25.                   Returns the temperature expressed in
  26.                   Fahrenheit.
  27. ---------------------------------------------------------}
  28. type
  29.  
  30. Temperature = object
  31.             Value : real;
  32.             procedure PutTemp( T : real; DegType : char );
  33.             function GetTempC : real;
  34.             function GetTempF : real;
  35.             end;
  36.  
  37. procedure Temperature.PutTemp( T : real; DegType : char );
  38. begin
  39.      Value := T;
  40.      if DegType = 'F' then
  41.         Value := (T - 32) * 5/9;
  42. end;
  43.  
  44.  
  45. function Temperature.GetTempC : real;
  46. begin
  47.           GetTempC := Value;
  48. end;
  49.  
  50.  
  51. function Temperature.GetTempF : real;
  52. begin
  53.           GetTempF := (Value * 9/5) + 32;
  54. end;
  55.  
  56.  
  57. var
  58.    A,B,C : Temperature;
  59.  
  60. begin
  61.     A.PutTemp(32,'F');
  62.     writeln('Temperature A is ', A.GetTempC:2:2, ' deg C');
  63.     writeln('Temperature A is ', A.GetTempF:2:2, ' deg F');
  64.  
  65.     B.PutTemp(100,'F');
  66.     writeln('Temperature B is ', B.GetTempC:2:2, ' deg C');
  67.     writeln('Temperature B is ', B.GetTempF:2:2, ' deg F');
  68.  
  69.     C.PutTemp( -40,'F');
  70.     writeln('Temperature C is ', C.GetTempC:2:2, ' deg C');
  71.     writeln('Temperature C is ', C.GetTempF:2:2, ' deg F');
  72.  
  73. end.
  74.  
  75.  
  76. { Listing 1-3 }
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.